//
//  MobileResetVC.m
//  EPTool
//
//  Created by guoshiqing on 2018/4/21.
//  Copyright © 2018年 云数动能科技. All rights reserved.
//

#import "MobileResetVC.h"
#import "MobileInputVC.h"

#import "Macro.h"
#import "UILabel+NameRole.h"
#import "UIView+DDAddition.h"
#import "StringUtil.h"
#import "EPButton.h"
#import "AccountSysVM.h"
#import "UserSettings.h"

@interface MobileResetVC ()
@property (nonatomic, strong) UIImageView *igvLogo;
@property (nonatomic, strong) UILabel *lblMobile;
@property (nonatomic, strong) EPButton *btnNext;
@property (nonatomic, strong) UILabel *lblDescMsg;

// 保存用户输入的密码
@property (nonatomic, strong) NSString *pwd;
@end

@implementation MobileResetVC

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"更换手机号";
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [self addSubviews];
}

#pragma mark - 接口调用返回结果处理
- (void)handelRequestData:(BaseJSONEntity *)returnValue
{
    [self hideProcessingHud];
    if (0 != returnValue.ret) {
        [self showAlertWithTitle:returnValue.msg];
        return;
    }
    MobileInputVC *mbInputVc = [[MobileInputVC alloc] init];
    mbInputVc.baseVM = [[AccountSysVM alloc] init];
    mbInputVc.type = ForModifyMobileType;
    mbInputVc.pwd = self.pwd;
    [mbInputVc setAreaCode:UserSaveInfo.areaCode andMobile:UserSaveInfo.mobile];
    [self.navigationController pushViewController:mbInputVc animated:YES];
}

#pragma mark - 完成点击下一步的代理事件
- (void)btnNextClick:(id)sender
{
    WEAKSELF
    [self showAlertForInputPwdSuccess:^(NSString * _Nonnull password) {
        weakSelf.pwd = password;
        if (weakSelf.baseVM) {
            [weakSelf showProcessingHud:@"..."];
            [(AccountSysVM *)weakSelf.baseVM checkPwdForModifyMobileWithAreaCode:UserSaveInfo.areaCode andMobile:UserSaveInfo.mobile andPwd:password];
        }
    } failure:^{
        // do nothings...
    }];
}

#pragma mark - 懒加载
- (UIImageView *)igvLogo
{
    if (!_igvLogo) {
        _igvLogo = [[UIImageView alloc] initWithFrame:CGRectMake(0, 42.f, 57.f, 113.f)];
        _igvLogo.image = [UIImage imageNamed:@"me_icon_phone"];
    }
    return _igvLogo;
}

- (UILabel *)lblMobile
{
    if (!_lblMobile) {
        _lblMobile = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, UI_SCREEN_WIDTH, 25.f)];
        _lblMobile.textAlignment = NSTextAlignmentCenter;
    }
    return _lblMobile;
}

- (EPButton *)btnNext
{
    if (!_btnNext) {
        _btnNext = [[EPButton alloc] initWithFrame:CGRectMake(Cell_X, 0, Cell_W, Cell_H)];
        [_btnNext setTitle:@"更换手机号" forState:UIControlStateNormal];
        _btnNext.epStyle = EPBasicButton_btn2;
    }
    return _btnNext;
}

- (UILabel *)lblDescMsg
{
    if (!_lblDescMsg) {
        _lblDescMsg = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, UI_SCREEN_WIDTH, 17.f)];
        _lblDescMsg.textColor = [EPColor epColor_descMessageGray];
        _lblDescMsg.textAlignment = NSTextAlignmentCenter;
        _lblDescMsg.font = SystemFont(12.f);
        _lblDescMsg.text = @"更换手机号说明";
    }
    return _lblDescMsg;
}

- (void)addSubviews
{
    self.view.backgroundColor = [EPColor epColor_Bg];
    
    [self.view addSubview:self.igvLogo];
    self.igvLogo.centerX = self.view.width/2;
    [self.view addSubview:self.lblMobile];
    self.lblMobile.top = self.igvLogo.bottom + 42.f;
    [self.view addSubview:self.btnNext];
    self.btnNext.top = self.lblMobile.bottom + 50.f;
    [self.view addSubview:self.lblDescMsg];
    self.lblDescMsg.top = self.btnNext.bottom + Cell_X;
    
    if ([UserSaveInfo.areaCode isEqualToString:@"86"]) {
        [self.lblMobile setName:@"您的手机号：" withNameColor:[EPColor epColor_TitleBlack] withNameFont:SystemFont(16.f) andRole:[StringUtil stringFormat334:UserSaveInfo.mobile] withRoleColor:[EPColor epColor_TitleBlack] withRoleFont:SystemFont(18.f)];
    }
    else
    {
        [self.lblMobile setName:@"您的手机号：" withNameColor:[EPColor epColor_TitleBlack] withNameFont:SystemFont(16.f) andRole:[StringUtil stringFormat44:UserSaveInfo.mobile] withRoleColor:[EPColor epColor_TitleBlack] withRoleFont:SystemFont(18.f)];
    }
    
    [self.btnNext addTarget:self action:@selector(btnNextClick:) forControlEvents:UIControlEventTouchUpInside];
}

@end
